<template>
  <view>
    <!-- 搜索框 -->
    <view class="search-box">
      <my-search @click="gotoSearch"></my-search>
    </view>
    <!-- 搜索框 -->
    <!-- 轮播图的区域 -->
    <swiper :indicator-dots="true" :autoplay="true" :interval="3000" :duration="1000" :circular="true">
      <swiper-item v-for="(item,i) in swiperList" :key="i">
        <navigator class="swiper-item" :url="'/subpkg/good_detail/good_detail?goods_id=' + item.goods_id">
          <image :src="item.image_src"></image>
        </navigator>
      </swiper-item>
    </swiper>
    <!-- 轮播图的区域 -->
    <!-- 分类的区域 -->
    <view class="classify">
      <view class="classify-item" v-for="(item,i) in navList" :key="i"  @click="handleNavigator(item)">
        <image :src="item.image_src"></image>
      </view>
    </view>
    <!-- 分类的区域 -->
    <!-- 楼层区域 -->
    <view class="floor">
      <view class="floor_tiltle" v-for="(item,i) in floorList"  :key="i">
        <image :src="item.floor_title.image_src" class="img1"></image>
        <view class="floor_img_box">
          <navigator class="left__img_box" :url="item.product_list[0].url">
            <image :src="item.product_list[0].image_src" :style=" {width:item.product_list[0].image_width+'rpx'}" mode="widthFix"></image>
          </navigator>
          <view class="right__img_box">
            <navigator class="right__img_item" v-for="(item2,i2) in item.product_list" :key="i2" v-if="i2 !== 0" :url="item2.url">
              <image class="img2" :src="item2.image_src" mode="widthFix" :style="{width:item2.image_width+'rpx'}"></image>
            </navigator>
          </view>
        </view>
      </view>
    </view>
    <!-- 楼层区域 -->
  </view>
</template>

<script>
  export default {
    data() {
      return {
        swiperList:[],
        navList:[],
        floorList:[]
      };
    },
    onLoad() {
      this.getSwiperList()
      this.getNavList()
      this.getFloorList()
    },
    methods:{
      async getSwiperList(){
        const { data: res } = await uni.$http.get('/api/public/v1/home/swiperdata')
        // console.log(res)
        // 如果请求失败
        if(res.meta.status !== 200) return uni.$showMsg()
        this.swiperList=res.message
      },
      async getNavList(){
         const {data: res}=await uni.$http.get('/api/public/v1/home/catitems')
         if(res.meta.status !== 200) return uni.$showMsg()
         this.navList = res.message
      },
      handleNavigator(item){
        // console.log(item)
        if(item.name === '分类'){
          uni.switchTab({
            url:'../cate/cate'
          })
        }
      },
      async getFloorList(){
        const {data: res} = await uni.$http.get('/api/public/v1/home/floordata')
        if(res.meta.status !== 200 ) return uni.$showMsg()
        res.message.forEach(floor => {
          floor.product_list.forEach(prod => {
            prod.url = '/subpkg/goods_list/goods_list?'+prod.navigator_url.split('?')[1]
          })
        })
        this.floorList=res.message
      },
      gotoSearch(){
        // console.log('ok')
        uni.navigateTo({
          url:'/subpkg/search/search'
        })
      }
      
    }
  }
</script>

<style lang="scss">
  .search-box{
    position: sticky;
    top: 0;
    z-index: 999;
  }
swiper{
  height: 330rpx;
  .swiper-item,image{
    width: 100%;
    height: 100%;
  }
}
.classify{
  display: flex;
  justify-content: space-around;
  margin: 15rpx 0;
  image{
    width: 128rpx;
    height: 140rpx;
  }
}
.floor_tiltle{
  .img1{
    height: 55rpx;
  }
}
.right__img_box{
  display: flex;
  justify-content: space-around;
  flex-wrap: wrap;
  
}
.floor_img_box{
  display: flex;
  padding-left: 10rpx;
}
</style>
